<template>
  <div class="msgBox">
     <van-form @submit="onSubmit">
  <van-field
    v-model="requestData.mateName"
    name="mateName"
    label="配偶姓名"
    placeholder="配偶姓名"
/>
  <van-field
    v-model="requestData.tel"
    name="tel"
    label="配偶手机号码"
    placeholder="配偶手机号码"
   
  />

   <gz-code-input @valueChange = valueChange :requestData='requestData' requestMethod='post' requestUrl=''  placeholder="验证码">
         
        </gz-code-input>
  <div >
    <van-button  block type="info"  native-type="submit">下一步</van-button>
  </div>
</van-form>
 <gz-authorization
         @input="input"
        :fileinfo="fileinfoRule"
        :identityinfo="identityinfoRule"
        v-model="isReadly"
      ></gz-authorization>
  </div>
</template>

<script>
import Vue from 'vue';
import { Form,Button,Field  } from 'vant';


Vue.use(Form);
Vue.use(Field);
Vue.use(Button)
export default {
data(){
    return{
      smsResults:'',
      dateResults:'',
   requestData:{
    mateName:JSON.parse(localStorage.getItem('mateMsgObj')).authorizedName || '',
    tel:JSON.parse(localStorage.getItem('mateMsgObj')).phoneNumber || '',
   instId:''
   },
     fileinfoRule: [
        { name: "对外提供个人信息授权书", key: "network" },
        // { name: "人脸识别授权书", key: "faceRecognition" },
        { name: "个人征信客户授权书", key: "creditInvestigation" },
        { name: "个人信息及敏感信息授权书", key: "sensitive" },
        { name: "纳税人涉税信息查询授权书", key: "information" },
        // { name: "共债说明书", key: "jointDebt" },
      ],
         identityinfoRule: {
        personalFlag: false, //（是否个人授权书）
        xtlsh:'', //（系统流水号）
        cardName:  JSON.parse(localStorage.getItem('mateMsgObj'))?JSON.parse(localStorage.getItem('mateMsgObj')).cardName:'', //（身份证类型名称）  000101
        cardCode: JSON.parse(localStorage.getItem('mateMsgObj'))?JSON.parse(localStorage.getItem('mateMsgObj')).cardCode:'', //（身份证号）
        authorizedName: JSON.parse(localStorage.getItem('mateMsgObj'))?JSON.parse(localStorage.getItem('mateMsgObj')).authorizedName:'', //（客户姓名）
      },
       isReadly: false,
    }
},
mounted(){

  this.requestData.instId =  this.getParam('instId')
  this.identityinfoRule.xtlsh = this.getParam('instId')
    this.baseService
                    .postForm(this.__ctx + "cifPer/exp/queryRes", {instId:this.requestData.instId,})
                    .then((res) => {
                     if (res.isOk) {
                      this.smsResults = res.data.smsResults
                      this.dateResults = res.data.dataResults
                     }
                      console.log(this.smsResults,this.dateResults);
                    })
                   
   
},
methods:{
  input(val){
    console.log(val);
    if (val) {
      this.dateResults = '1'
    }else{
      this.dateResults = '0'
    }
  },
    getParam(name) {
        var locUrl = window.location.search.substr(1);
        var aryParams = locUrl.split("&");
        var rtn = "";
        for (var i = 0; i < aryParams.length; i++) {
          var pair = aryParams[i];
          var aryEnt = pair.split("=");
          var key = aryEnt[0];
          var val = aryEnt[1];
          if (key != name) continue;
          if (rtn == "") {
            rtn = val;
          } else {
            rtn += "," + val;
          }
        }
        return rtn;
      },
  valueChange(val){
   
    if (val.length>5) {
       this.baseService
                    .post(this.__ctx + "/message/checkCode", {instId:this.requestData.instId,tel:this.requestData.tel,credential:val})
                    .then((res) => {
                   if (res.isOk) {
                      this.smsResults = '1'
                      this.$vux.toast.show({
                       text: '校验成功',
                      })
                      
                    }else{
                       this.smsResults = '0'
                      this.$vux.toast.show({
                       text: '校验失败',
                      })
                    }
                    })
    }
      
  },
   onSubmit(values) {
      console.log('submit', values);
      if (this.smsResults != '1') {
         this.$vux.toast.show({
                       text: '请进行短信验证',
                      })
                      return false
      }
       if (this.dateResults != '1') {
         this.$vux.toast.show({
                       text: '请阅读相关规则',
                      })
                      return false
      }
      this.baseService
                    .postForm(this.__ctx + "/cifPer/exp/saveDateSmsRes", {instId:this.requestData.instId,dataResults:this.dateResults,smsResults:this.smsResults})
                    .then((res) => {
                    console.log(res);
                    })
                    this.$router.push({
                        path:'/auth/verifyFace',  
                        query: {
                        instId : this.requestData.instId  //参数
                        }
                    })
     
    },
}
}
</script>

<style lang='less' scoped>
.msgBox{

   display: flex;
    justify-content: space-between;
    
    flex-direction: column;
}
.van-button--block{
  position: fixed;
  bottom: 0;
  background-color: rgb(204, 52, 0);
  border: none;
}
.van-form{
  margin-top: 20px;
}
</style>